package com.zhao.biz.tag.perform

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.Row

/**
 * Description: 关键字匹配<br/>
 * Copyright (c) ，2021 ， 赵 <br/>
 * A wet person does not fear the rain. <br/>
 * Date： 2021/1/14 15:03
 * 关键字(标签格式: Kxxx->1) xxx 为关键字,关键字长度不能少于3个字符,且不能
 * 超过8个字符;关键字中包含"|",则分隔成数组,转换成功过多个关键字标签
 *
 * @author 柒柒
 * @version : 1.0
 */

object TagsKeyword extends IMakeTags {
  /**
   * 数据标签接口
   *
   * @param args
   * @return
   */
  override def makeTags(args: Any*): List[(String, Int)] = {

    var list: List[(String, Int)] = List[(String, Int)]()

    //分析
    val row: Row = args(0).asInstanceOf[Row]

    val stopWordContainer: Map[String, Int] = args(1).asInstanceOf[Broadcast[Map[String, Int]]].value

    val arr: Array[String] = row.getAs[String]("keywords").split("\\|")

    arr.foreach(perKeyWord =>{
      val len = perKeyWord.length
      val isInStopWordContainer: Boolean = stopWordContainer.contains(perKeyWord)
      if((len >= 3 && len <= 8) && !isInStopWordContainer) {
        list :+= (perKeyWord,1)
      }
    })

    list
  }
}






















